function gme_test
SLICE_NUM   = 3;

P = [];
vec_h_array = [];
vec_v_array = [];

for k=1:60
    display('.');
  tmpVideo = mmread('gladiator.mpg',k:k,[],false,true,'',false,true);% SlippingGirl_24P.mpg
  frameY = tmpVideo.frames.cdata(:,:,1); 
  Y1 = double(frameY);
  if k == 1
     [P1,SAD,VEC] = gme(Y1,P,1,1);
  else
     P = P1;
     VEC_H = [];
     VEC_V = [];
     for slice = 1:SLICE_NUM 
         [P1,SAD,VEC] = gme(Y1,P,slice,0);
         VEC_H = [VEC_H,VEC(1:slice)];
         VEC_V = [VEC_V,VEC(slice+1:2*slice)];
     end
     vec_h_array = [vec_h_array,GetFinnalVEC(VEC_H)];
     vec_v_array = [vec_v_array,GetFinnalVEC(VEC_V)];
  end
end

vec_x = vec_h_array
vec_y = vec_v_array

debug = 0;
if debug == 1
   tmpVideo = mmread('SlippingGirl_24P.mpg',1:1,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = ones(1000,1000);
   Y1 = double(frameY);
   [P1,SAD1,VEC1] = gme(Y1,P,slice,1);

   tmpVideo = mmread('SlippingGirl_24P.mpg',2:2,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1);
   %frameY = Shift(frameY,31,-31);
   Y1 = double(frameY);
   [P2,SAD2,VEC2] = gme(Y1,P1,slice,0);

   tmpVideo = mmread('SlippingGirl_24P.mpg',3:3,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,30,-31);
   Y1 = double(frameY);
   [P3,SAD3,VEC3] = gme(Y1,P2,slice,0);
   
   tmpVideo = mmread('SlippingGirl_24P.mpg',4:4,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,31,-31);
   Y1 = double(frameY);
   [P4,SAD4,VEC4] = gme(Y1,P3,slice,0);

   tmpVideo = mmread('SlippingGirl_24P.mpg',5:5,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,31,31);
   Y1 = double(frameY);
   [P5,SAD5,VEC5] = gme(Y1,P4,slice,0);

   tmpVideo = mmread('SlippingGirl_24P.mpg',6:6,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,31,31);
   Y1 = double(frameY);
   [P6,SAD6,VEC6] = gme(Y1,P5,slice,0);

   tmpVideo = mmread('SlippingGirl_24P.mpg',7:7,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,31,31);
   Y1 = double(frameY);
   [P7,SAD7,VEC7] = gme(Y1,P6,slice,0);

   tmpVideo = mmread('SlippingGirl_24P.mpg',8:8,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,31,31);
   Y1 = double(frameY);
   [P8,SAD8,VEC8] = gme(Y1,P7,slice,0);

   tmpVideo = mmread('SlippingGirl_24P.mpg',9:9,[],false,true,'',false,true);
   frameY = tmpVideo.frames.cdata(:,:,1); 
   %frameY = Shift(frameY,31,31);
   Y1 = double(frameY);
   [P9,SAD9,VEC9] = gme(Y1,P8,slice,0);
end

end

function  vec_out = GetFinnalVEC(vec_in)
   THR_VEC_VAL = 5;
   THR_VEC_CNT = 4;
   vec_in  = sort(vec_in);
   vec_len = length(vec_in);
   mid     = vec_in(vec_len/2);
   cnt = 0;
   for k=1:vec_len
       if abs(vec_in(k)-mid) < THR_VEC_VAL
          cnt = cnt+1;
       end
   end
   if cnt >= THR_VEC_CNT
       vec_out = mid;
   else
       vec_out = 999999; 
   end  
end

